# -*- coding: utf-8 -*-

from openerp import models, fields, api
from openerp.report import report_sxw
from openerp.osv import osv


class SubbarDemo(models.Model):
    _name = 'subbar_demo.subbar_demo'

    INVENTORY_STATE_SELECTION = [
        ('draft', '草稿'),
        ('cancel', '取消'),
        ('confirm', '确认'),
        ('complete', '完成'),
    ]

    name = fields.Char(string="姓名")
    age = fields.Char(string="年龄")
    sex = fields.Char(string="性别")
    state = fields.Selection(INVENTORY_STATE_SELECTION, '状态', default='draft', readonly=True, select=True, copy=False)

    @api.one
    def do_draft(self):
        self.state = 'confirm'
        # self.write({'state': 'confirm'})
        return True

    @api.one
    def do_cancel(self):
        self.state = 'draft'
        return True

    @api.one
    def do_confirm(self):
        self.state = 'complete'
        return True

    @api.one
    def do_complete(self):
        self.state = 'complete'
        return True


class DomainDemo(models.Model):
    _name = "domain_demo.domain_demo"

    FRIEND_DOMAIN_SELECTION = [
        ('A', 'SAM'),
        ('B', 'AMY'),
        ('C', 'LINDA'),
        ('D', 'DAMING'),
    ]

    name = fields.Char(string="姓名")
    age = fields.Char(string="年龄")
    sex = fields.Char(string="性别")
    date = fields.Char(string="生日")
    friend1 = fields.One2many("subbar_demo.subbar_demo", "sex", string="朋友们")
    # friend2 = fields.Selection(FRIEND_DOMAIN_SELECTION, '朋友2', default='B', readonly=True, select=True, copy=False)


class WorkflowDemo(models.Model):
    _name = 'workflow_demo.workflow_demo'

    WORKFLOW_STATE_SELECTION = [
        ('draft', '开始'),
        ('confirm', '确认'),
        ('complete', '完成'),
    ]

    name = fields.Char(string="姓名")
    state = fields.Selection(WORKFLOW_STATE_SELECTION, '状态', default='draft', readonly=True, select=True, copy=False)

    @api.one
    def do_draft(self):
        self.state = 'confirm'
        # self.write({'state': 'confirm'})
        print "------------self.state = 'confirm'"
        return True

    @api.one
    def do_confirm(self):
        print "------------self.state = 'complete'"
        self.state = 'complete'
        return True

    @api.one
    def do_complete(self):
        print "------------complete!!!!!!!!'"
        return True


class GraphDemo(models.Model):
    _name = "graph_demo.graph_demo"

    name = fields.Char(string="姓名")
    age = fields.Char(string="年龄")
    man_count = fields.Integer(string="Attendees count", default=6)
    x_line = fields.Integer(string="X", default=6)
    y_line = fields.Integer(string="Y", default=6)


class GanttDemo(models.Model):
    _name = "gantt_demo.gantt_demo"

    name = fields.Char(string="名称")
    group = fields.Char(string="小组")
    start_date = fields.Date(string="开始日期", store=True)
    end_date = fields.Date(string="结束日期", store=True)
    hours = fields.Float(string="持续时间")
    progress = fields.Integer(string="进度", default=80)
    color = fields.Many2one("graph_demo.graph_demo", String="关联动作")


# class report_trialbalance(osv.AbstractModel):
#     _name = 'report.gantt_demo.gantt_demo.gantt_demo.report_session'
#     _inherit = 'report.abstract_report'
#     _template = 'gantt_demo.report_session_view'
#     _wrapped_report_class = account_balance
# class ParticularReport(models.AbstractModel):
#     _name = 'report.gantt_demo.report_view'
#     _inherit = 'report.abstract_report'
#     _template = 'gantt_report_view'
    # @api.multi
    # def render_html(self, data=None):
    #     report_obj = self.env['report']
    #     report = report_obj._get_report_from_name('gantt_demo.report_view')
    #     docargs = {
    #         'doc_ids': self._ids,
    #         'doc_model': report.model,
    #         'docs': self,
    #     }
    #     return report_obj.render('gantt_demo.report_view', docargs)
